import * as mobx from 'mobx';
import { observable, action, useStrict, computed, asMap } from 'mobx';

export class RejectStore{

    baseParams = {};
    chooseInfo = {};
    @observable rejectNodeList = [];
    @observable remindNodeList = [];
    @observable rejectNodeOperators = {};//退回节点的操作者
    @observable showAllRejectNodeOperators = {};
    @observable remindNodeOperators = {};//提醒节点的操作者
    @observable showAllRemindNodeOperators = {};
    @observable isSubmitDirectOptions = [];//用户选择退回后再提交的处理方式选项
    confirmEvent = null;
    cancelEvent = null;
    @observable result = {};

    constructor(){
        this.setBaseParams = this.setBaseParams;
        this.doInit = this.doInit;
        this.setConfirmEvent = this.setConfirmEvent;
        this.setCancelEvent = this.setCancelEvent;
        this.appendResult = this.appendResult;
        this.setShowAllRejectNodeOperators = this.setShowAllRejectNodeOperators;
        this.setShowAllRemindNodeOperators = this.setShowAllRemindNodeOperators;
    }

    @action
    setBaseParams = (params={}) => {
        this.baseParams = params;
    }

    @action
    setChooseInfo = (info={}) => {
        this.chooseInfo = info;
    }

    doInit = () => {
        this.result = {};
        const { checkedRejectNodeKey,rejectNodeList,remindNodeList,submitDirectNodeOptions,rejectNodeOperators,remindNodeOperators } = this.chooseInfo;
        let remindNodeid = "";
        remindNodeList && remindNodeList.map((item,index) =>{
            remindNodeid += (index > 0 ? "," : "") + item.key;
        });
        this.appendResult({rejectNodeKey:checkedRejectNodeKey, remindNodeid:remindNodeid});
        this.rejectNodeList = rejectNodeList;
        this.remindNodeList = remindNodeList;
        this.rejectNodeOperators = rejectNodeOperators;
        this.remindNodeOperators = remindNodeOperators;
        this.showAllRejectNodeOperators = {};
        this.showAllRemindNodeOperators = {};
        this.isSubmitDirectOptions = submitDirectNodeOptions;
        this.isSubmitDirectOptions && this.isSubmitDirectOptions.map(option => {
            if(option.selected == true) {
                this.appendResult({isSubmitDirect:option.key});
            }
        });
    }

    setConfirmEvent = (fun) => {
        this.confirmEvent = fun;
    }

    setCancelEvent = (fun) => {
        this.cancelEvent = fun;
    }

    appendResult = (obj={}) => {
        this.result = {...this.result, ...obj};
    }

    setShowAllRejectNodeOperators = (key)  => {
        const showAllRejectNodeOperators = {...this.showAllRejectNodeOperators, [key] : !this.showAllRejectNodeOperators[key]};
        this.showAllRejectNodeOperators = showAllRejectNodeOperators;
    }

    setShowAllRemindNodeOperators = (key)  => {
        const showAllRemindNodeOperators = {...this.showAllRemindNodeOperators, [key] : !this.showAllRemindNodeOperators[key]};
        this.showAllRemindNodeOperators = showAllRemindNodeOperators;
    }

}